import qqmap from "../../../utils/qqmap";
Page({
  data: {
    points: [],
    address: ''
  },
  onLoad() {
    this.getLocation()

  },
  async getLocation() {
    const { latitude, longitude } = await wx.getLocation()
    this.getPoint(latitude, longitude)
  },
  async chooseLocation() {
    const { latitude, longitude } = await wx.chooseLocation()
    this.getPoint(latitude, longitude)
  },
  getPoint(latitude, longitude) {
    qqmap.reverseGeocoder({
      location: [latitude, longitude].join(','),
      success: (res) => {
        this.setData({ address: res.result.address })
      }
    })
    qqmap.search({
      keyword: '住宅小区',
      location: [latitude, longitude].join(','),
      page_size: 5,
      success: (res) => {
        const points = res.data.map(({ id, title, _distance }) => {
          return { id, title, _distance }
        })
        this.setData({ points })
      },
      fail: (error) => {
        console.log(error.message);
      }
    })
  }
})